<?php
	getHeader();
?>

	<div class="main">
		<div class="tabs headTabs"><span>搜索结果</span></div>
	
<?php
			if (!isset($_GET['keyword']) || $_GET['keyword'] == '')
			{
?>
				<div class="dataList"><span>错误: 未定义关键词.</span></div>
			</div>
<?php
			}
			else if (isset($_GET['type']) && ($_GET['type'] == 'userNickname' || $_GET['type'] == 'userCollege' || $_GET['type'] == 'userTag'))
			{
?>
				<div class="dataList">
					<ul>
<?php
						$conn = new mysqlClass(DBHOST, DBUSER, DBPWD, DBNAME);
						$query = "SELECT * FROM users WHERE {$_GET['type']} LIKE '%{$_GET['keyword']}%';";
						$conn->query($query);
						if ($conn->row == 0)
						{
?>
							<li>没有找到搜索结果</li>
<?php
						}
						else
						{
							for ($i = 0;$i < $conn->row;$i++)
							{
								$conn->fetch($i);
?>
								<li>
									<ul>
										<li>
											<a href='<?php echo '?p=viewUser&uid='.$conn->data['uid']; ?>'><?php echo $conn->data['userNickname']; ?></a>
										</li>
										<li>
											<span>院系: <a href='?p=search&type=userCollege&keyword=<?php echo $conn->data['userCollege']; ?>'><?php echo $conn->data['userCollege']; ?></a></span>
										</li>
										<li>
											<span> 个人标签: 
<?php 
												$arr = userTagSeparate($conn->data['userTag']);foreach ($arr as $value)
												{
													echo "<a href='?p=search&type=userTag&keyword={$value}'>{$value}</a>&nbsp;&nbsp;";
												}
?>
											</span>
										</li>
									</ul>
								</li>
<?php
							}
						}
?>
					</ul>
				</div>
			</div>
<?php
			}
			else if (isset($_GET['type']) && $_GET['type'] == 'competitionName')
			{
?>
				<div class="dataList">
					<ul>
<?php
						$conn = new mysqlClass(DBHOST, DBUSER, DBPWD, DBNAME);
						$query = "SELECT cid,competitionName,competitionLevel FROM competitions WHERE {$_GET['type']} LIKE '%{$_GET['keyword']}%';";
						$conn->query($query);

						if ($conn->row == 0)
						{
?>
							<li>没有找到搜索结果</li>
<?php
						}
						else
						{
							for ($i = 0;$i < $conn->row;$i++)
							{
								$conn->fetch($i);
								$cur = new mysqlClass();
								$query = "SELECT uid FROM focus WHERE cid={$conn->data['cid']};";
								$cur->query($query);
?>
								<li>
									<ul>
										<li>
											<a href='<?php echo '?p=viewCompetition&cid='.$conn->data['cid']; ?>'><?php echo $conn->data['competitionName']; ?></a>
										</li>
										<li>
											<span>
												级别: <?php echo "{$conn->data['competitionLevel']}"; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
												参与人数:<?php echo $cur->row; ?>
											</span>
										</li>
									</ul>
								</li>
<?php
							}
						}
?>
					</ul>
				</div>
			</div>
<?php
		}
	getPanel();
	getFooter();
?>